package com.ctgu.rabbitmq.service.impl;

import com.ctgu.rabbitmq.rabbitmq.workQueue.WorkQueueConfig;
import com.ctgu.rabbitmq.service.WorkQueueService;
import com.ctgu.rabbitmq.utils.ApiResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

/**
 * @ ClassName WorkQueueServiceImpl
 * @ Author Alex2
 * @ Date 2025/8/23 16:15
 **/
@Log4j2
@Service
public class WorkQueueServiceImpl implements WorkQueueService {

    private final RabbitTemplate rabbitTemplate;

    public WorkQueueServiceImpl(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    @Override
    public ApiResult workQueue() {
        String[] types = {"IMAGE_", "VIDEO_"};
        for (int i = 0; i < 8; i++) {
            String type = types[i % 2];
            rabbitTemplate.convertAndSend(WorkQueueConfig.WORK_QUEUE, type + i);
        }
        return ApiResult.success("消息发送成功");
    }
}